# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Contributor: Alexey Minnekhanov <alexeymin@postmarketos.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=qt-creator
pkgver=13.0.0
pkgrel=0
pkgdesc="Lightweight and cross-platform C++ IDE"
url="https://qt-project.org/wiki/Category:Tools::QtCreator"
arch="x86_64 aarch64" # qt6-qtwebengine
license="GPL-3.0-only WITH Qt-GPL-exception-1.0"
depends="
	qt6-qtbase-sqlite
	qt6-qtbase-dev
	qt6-qttools-dev
	"
_llvmver=17
makedepends="
	botan-dev
	clang$_llvmver-dev
	clang$_llvmver-static
	cmake
	elfutils-dev
	lld
	llvm$_llvmver-dev
	llvm$_llvmver-gtest
	llvm$_llvmver-static
	qt6-qt5compat-dev
	qt6-qtdeclarative-dev
	qt6-qtquick3d-dev
	qt6-qtserialport-dev
	qt6-qtshadertools-dev
	qt6-qtsvg-dev
	qt6-qtwebengine-dev
	samurai
"
ldpath="/usr/lib/qtcreator:/usr/lib/qtcreator/plugins"
source="
	https://download.qt.io/official_releases/qtcreator/${pkgver%.*}/$pkgver/qt-creator-opensource-src-$pkgver.tar.xz
	fix-execinfo.patch
	fix-malloc-trim.patch
	"

builddir="$srcdir"/qt-creator-opensource-src-$pkgver

build() {
	# enum-constexpr-conversion in clang16 now flags outside-enumeration
	# values like -1 as invalid
	export CC=clang-$_llvmver
	export CXX=clang++-$_llvmver
	export CFLAGS="$CFLAGS -flto=thin"
	export CXXFLAGS="$CXXFLAGS -flto=thin -Wno-error=enum-constexpr-conversion -I/usr/lib/llvm$_llvmver/include"
	export LDFLAGS="$LDFLAGS -fuse-ld=lld"

	case "$CARCH" in
	aarch64)
		# not recognised by clang on aarch64
		export CFLAGS="${CFLAGS/-fstack-clash-protection}"
		export CXXFLAGS="${CXXFLAGS/-fstack-clash-protection}"
		;;
	esac
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_QBS=OFF \
		-DBUILD_PLUGIN_CLANGFORMAT=OFF \
		-DBUILD_PLUGIN_COPILOT=OFF \
		-DBUILD_WITH_PCH=OFF \
		-DCLANGTOOLING_LINK_CLANG_DYLIB=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
26fea156becc136fb55702a65c29dad825fd3fa60d8e19d8d142ab6518dc8e40fbddfe70d79d2b71f14f76c8a1d9bca34fb65e565702e67c9276aec9758bf345  qt-creator-opensource-src-13.0.0.tar.xz
43d73c9cd272ee849a5d85490d351c71b786d7ce6b5b46c6ec13642329c14bacc84a122f0bfbb445841aedef8d1cc9fe2485c0c8db24080b5a9dd4380e36c58d  fix-execinfo.patch
efb137318e7005beb4c01cb27dcfc49d63b5c6faa66b0a6d6989bb6533ca94875e34880c482ce36f699dadf920b55a3de43eeed4fa5cf98d1b56405ee2ff0aa5  fix-malloc-trim.patch
"
